[ACR] az acr login: harden binary resolution and credential passing#33373
[ACR] az acr login: harden binary resolution and credential passing#33373lizMSFT wants to merge 2 commits into
Conversation
|
Validation for Azure CLI Full Test Starting...
Thanks for your contribution! |
|
Validation for Breaking Change Starting...
Thanks for your contribution! |
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
There was a problem hiding this comment.
Pull request overview
Hardens az acr login by validating the resolved docker/podman binary path (rejecting binaries located directly in CWD) and switching credential passing from --password (CLI arg, visible in process listings) to --password-stdin (piped via stdin). The get_docker_command flow is also refactored into smaller helpers and a DOCKER_COMMAND env var is honored as a trusted absolute-path override.
Changes:
- Switch
_perform_registry_loginto--password-stdinwithBrokenPipeError/OSErrorhandling and an updated wincred retry path. - Add
_validate_command_pathto refuse binaries resolved from CWD, with a diagnostics-mode soft path; integrate it into a new_resolve_docker_commandhelper plus_try_wsl_exe_fallback. - Add a unit test module covering CWD-block, system-path-allow, Windows-path, diagnostics, and symlink-bypass cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/azure-cli/azure/cli/command_modules/acr/custom.py | Refactors get_docker_command, adds CWD path validation, switches docker login to --password-stdin. |
| src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_docker_path_validation.py | New unit tests covering _validate_command_path behavior on POSIX, Windows, diagnostics, and symlink scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dffabd8 to
e1e8b72
Compare
e1e8b72 to
493af3a
Compare
| resolved_path = shutil.which(docker_command) | ||
| if resolved_path: | ||
| try: | ||
| # Use the pre-symlink path for the security decision to prevent symlink bypass |
There was a problem hiding this comment.
Can you clarify a bit why we choose to check pre-symlink path not the real path? If the real path is in current working folder, is it ok?
Check both abspath (where PATH found the binary) and realpath (where the symlink ultimately points) against the CWD. This blocks both: - A symlink in CWD pointing elsewhere (caught by abspath) - A binary elsewhere that symlinks into the CWD (caught by realpath) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Related command
az acr loginDescription
Harden Docker/Podman binary resolution and credential passing in
az acr login:--password(command-line argument) to--password-stdin(stdin pipe)DOCKER_COMMANDenvironment variable support for specifying a trusted absolute path to the binaryget_docker_command()into smaller helper functions for clarityTesting Guide
History Notes
[ACR] az acr login: Harden binary resolution and credential passing
This checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.